<template>
  <transition name="popup-slide-up">
    <div class="ebook-popup-list" v-show="fontFamilyVisible">
      <div class="ebook-popup-title">
        <div class="ebook-popup-title-icon" @click="hide">
          <span class="icon-down2"></span>
        </div>
        <span class="ebook-popup-title-text">{{$t('book.selectFont')}}</span>
      </div>
      <div class="ebook-popup-list-wrapper">
        <div
          class="ebook-item"
          v-for="(item, index) in fontFamilyList"
          :key="index"
          @click="setFontFamily(item)"
        >
          <div class="ebook-popup-item-text" :class="{'selected': isSelected(item)}">{{ item.font }}</div>
          <div class="ebook-popup-item-check" v-if="isSelected(item)">
            <span class="icon-check"></span>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>
<script>
import { FONT_FAMILY } from "../../utils/book";
import { ebookMixin } from "../../utils/mixin";
import { saveFontFamily } from '../../utils/localStorage'
export default {
  mixins: [ebookMixin],
  data() {
    return {
      fontFamilyList: FONT_FAMILY
    };
  },
  mounted() {},
  methods: {
    hide() {
      // 控制字体窗口的隐藏
      this.setFontFamilyVisible(false);
    },
    isSelected(item) {
      // 控制当前字体选中
      return this.defaultFontFamily === item.font;
    },
    setFontFamily(item) {
      // 点击字体 选中
      this.setDefaultFontFamily(item.font);
      saveFontFamily(this.fileName, item.font) // 存储到本地，刷新后不会消失
      if (item.font === "Default") {
        this.currentBook.rendition.themes.font('Times New Roman');
      } else {
        this.currentBook.rendition.themes.font(item.font);
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "../../assets/styles/global";
.ebook-popup-list {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 300;
  width: 100%;
  background-color: #fff;
  box-shadow: 0 px2rem(-4) px2rem(6) rgba(0, 0, 0, 0.1);
  .ebook-popup-title {
    position: relative;
    padding: px2rem(15);
    box-sizing: border-box;
    border-bottom: px2rem(1) solid #b8b9bb;
    text-align: center;
    @include center;
    .ebook-popup-title-icon {
      position: absolute;
      left: px2rem(15);
      top: 0;
      height: 100%;
      font-size: px2rem(16);
      font-weight: bold;
      @include center;
    }
    .ebook-popup-title-text {
      font-size: px2rem(14);
      font-weight: bold;
    }
  }
  .ebook-popup-list-wrapper {
    .ebook-item {
      display: flex;
      justify-content: space-between;
      padding: px2rem(15);
      .ebook-popup-item-text {
        font-size: px2rem(14);
        &.selected {
          color: #346cb9;
          font-weight: bold;
        }
      }
      .ebook-popup-item-check {
        font-size: px2rem(14);
        color: #346cb9;
      }
    }
  }
}
</style>